package com.example.goods_service.controller;

import com.example.goods_service.return_data.Mall_Data;
import com.example.goods_service.service.GoodsService_liyongjie;
import com.example.goods_service.vo.T_commodity;
import com.example.goods_service.vo.T_commodity_category;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api
public class GoodsController_liyongjie {

    @Autowired
    GoodsService_liyongjie liyongjie;

    Mall_Data mall_data = new Mall_Data();

    @ApiOperation("添加商品类别")
    @RequestMapping("/inseleibie")
    public Mall_Data insecat(T_commodity_category category){
        if (category.getName() != null){
            return mall_data.setdata(liyongjie.insertcat(category));
        }
        return null;
    }

    @ApiOperation("修改商品类别")
    @RequestMapping("/updaleibie")
    public Mall_Data updacat(T_commodity_category category){
        if (category.getName() != null){
            return mall_data.setdata(liyongjie.updatecat(category));
        }
        return null;
    }

    @ApiOperation("删除商品类别")
    @RequestMapping("/deleleibie")
    public Mall_Data delecat(T_commodity_category category){
        if (category.getId() != 0){
            liyongjie.deletecatpid(category);
            return mall_data.setdata(liyongjie.deletecat(category));
        }
        return null;
    }

    @ApiOperation("查询商店商品")
    @RequestMapping("/selecom")
    public Mall_Data selectcom(){
        return  mall_data.setdata(liyongjie.selectcom());
    }

    @ApiOperation("修改商品状态，启用或停用")
    @RequestMapping("/updacom")
    public Mall_Data updacom(T_commodity commodity){
        if (commodity.getId() != 0) {
            return mall_data.setdata(liyongjie.updacom(commodity));
        }
        return null;
    }

    @ApiOperation("商家页面删除商品")
    @RequestMapping("/deletecom")
    public Mall_Data delecom(T_commodity commodity){
        if (commodity.getId() != 0) {
            return mall_data.setdata(liyongjie.deletecom(commodity));
        }
        return null;
    }

}
